package me.gijspennings.jumpandduck.graphics;

public class Sprite {

    public static Sprite darkStone = new Sprite(SpriteSheet.tiles, 16, 16, 0, 0);
    public static Sprite lightStone = new Sprite(SpriteSheet.tiles, 16, 16, 1, 0);
    
    public static final int DEFAULT_SIZE = 16;
    public static final int TRANSPARENT_COLOR = 0xFFFF00FF;
    
    protected final SpriteSheet spritesheet;
    protected final int width, height;
    public int[] pixels;
    
    private Sprite(SpriteSheet spritesheet, int width, int height, int x, int y) {
        this.spritesheet = spritesheet;
        this.width = width;
        this.height = height;
        pixels = loadSprite(x, y);
    }
    protected Sprite(SpriteSheet spritesheet, int width, int height) {
        this.spritesheet = spritesheet;
        this.width = width;
        this.height = height;
    }
    
    protected int[] loadSprite(int x, int y) {
        int[] pixels = new int[width * height];
        x = x * Sprite.DEFAULT_SIZE;
        y = y * Sprite.DEFAULT_SIZE;
        for (int yy = 0; yy < height; yy++) {
            for (int xx = 0; xx < width; xx++) {
                pixels[xx + yy * width] = spritesheet.pixels[(x + xx) + (y + yy) * spritesheet.getWidth()];
            }
        }
        return pixels;
    }
    
    public SpriteSheet getSpriteSheet() {
        return spritesheet;
    }
    public int getWidth() {
        return width;
    }
    public int getHeight() {
        return height;
    }
    
}
